package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.LogininfoBean;
import cn.xfdzx.android.apps.shop.bean.VersionInfoBean;
import cn.xfdzx.android.apps.shop.contract.OtherLoginContract;
import cn.xfdzx.android.apps.shop.contract.VersionInfoContract;
import cn.xfdzx.android.apps.shop.model.OtherLoginModel;
import cn.xfdzx.android.apps.shop.model.VersionInfoModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author zf
 * @date 2020/6/27.
 * Description：
 */
public class VersionInfoPresenter extends BasePresenter<VersionInfoContract.View> implements VersionInfoContract.Presenter {

    private VersionInfoContract.Model model;

    public VersionInfoPresenter() {
        model = new VersionInfoModel();
    }

    @Override
    public void getVersionInfo() {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getVersionInfo()
                .compose(RxScheduler.<VersionInfoBean>Flo_io_main())
                .as(mView.<VersionInfoBean>bindAutoDispose())
                .subscribe(new Consumer<VersionInfoBean>() {
                    @Override
                    public void accept(VersionInfoBean bean) throws Exception {
                        mView.onVersionInfoSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
